/**
 * Created by wenchuan.li on 2018/7/12 14:23.
 */
define(function () {

    var self,
        app = win.app,
        pageArgs,
        g_pgx = [] //评估项列表
    ;

    var Gjpgx = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _readyBefore: function () {
                    pageArgs = self._pageParameters;
                }
            }, win);

        },
        getPgx: function () {//评估项列表
            app.ajax({
                xurl: "api/wx/gwa/getGjpgx",
                // ocache:true,
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data;
                        data.addMap({ischecked:false});
                        g_pgx.pushArray(data, true);
                        if(pageArgs.pgx.length==0){
                            self.getPgx1();
                        }else{
                            pageArgs.pgx.forEach(function (p1, p2, p3) {
                                g_pgx.filterKV({GWBC001: p1.GWBL001}).addMap({ischecked:true}, true);
                            });
                        }
                    }
                }
            });
        },
        getPgx1: function () {//根据主题+客户获取已有的 评估值
            app.ajax({
                xurl: "api/wx/gwat161/getPgz",
                xdata:{
                    GWBLID: pageArgs.GWBLID,
                    GWBLNAME:pageArgs.GWBLNAME
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data.data;
                        data.forEach(function (p1, p2, p3) {
                            g_pgx.filterKV({GWBC001: p1.GWBL001}).addMap({ischecked:false}, true);
                        });
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            self.getPgx();
        },
        _ready: function () {
            new Vue({
                el: app.getByid(doc,'mainNumber'),
                data: {
                    pgx: g_pgx
                },
                methods: {
                    checkItem:function (item) {
                        item.ischecked = !item.ischecked;
                    },
                    sure: function () {
                        pageArgs.pgx.pushArray(g_pgx.filterKV({ischecked:true}),true);
                        pageArgs.cb(g_pgx);
                        app.back(1);
                    }
                }
            });

            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        }
    });

    new Gjpgx();

});